package com.UI
{
	import com.*;
	import com.Engine.*;
	import com.Packet.*;
	import com.UI.*;
	
	import flash.display.*;
	import flash.display.BitmapData;
	import flash.events.*;
	import flash.external.*;
	import flash.filters.*;
	import flash.geom.*;
	import flash.net.*;
	import flash.system.*;
	import flash.text.*;
	import flash.ui.*;
	import flash.utils.*;
	import flash.utils.ByteArray;
	import flash.utils.getQualifiedClassName;
	
	import org.aswing.*;
	import org.aswing.border.*;
	import org.aswing.border.EmptyBorder;
	import org.aswing.colorchooser.*;
	import org.aswing.dnd.*;
	import org.aswing.event.*;
	import org.aswing.ext.*;
	import org.aswing.geom.*;
	import org.aswing.graphics.*;
	import org.aswing.tree.AbstractLayoutCache;
	
	public class PanelSmallMap extends JPanel
	{
		/**
		 * 显示小地图用的位图
		 */ 
		private var _bitmap:Bitmap;
		/**
		 * 小地图的位图数据
		 */ 
		private var _bitmapdata:BitmapData;
		
		public function PanelSmallMap()
		{
			//component creation
			setSize(new IntDimension(170, 73));
			//setPreferredSize(new IntDimension(43, 43));
			var layout0:EmptyLayout = new EmptyLayout();
			setLayout(layout0);
			
			//5,5,170,63
			
			_bitmapdata = new BitmapData(170,63,false,0);
			_bitmap = new Bitmap(_bitmapdata);
			_bitmap.x = 5;
			_bitmap.y = 5;
			addChild(_bitmap);
		}
		public function update():void
		{
			if(SceneMain.getInstance().map == null)return;
			if(SceneMain.getInstance().map.smallMap == null)return;
			//_bitmapdata.copyPixels(SceneMain.getInstance().map.smallMap,new Rectangle(0,0,170,73),new Point(0,0));
			var centerPoint:Point = SceneMain.getInstance().focusObject.getPos();
			
			var mWidth:Number = SceneMain.getInstance().map.smallMap.width / SceneMain.getInstance().map.mapWidth;
			var mHeight:Number = SceneMain.getInstance().map.smallMap.height / SceneMain.getInstance().map.mapHeight;
			
			var startX:int = centerPoint.x * mWidth-_bitmapdata.width/2;
			var startY:int = centerPoint.y * mHeight-_bitmapdata.height/2;
			if(startX < 0)startX = 0;
			if(startY < 0)startY = 0;
			if(startX > SceneMain.getInstance().map.smallMap.width - _bitmapdata.width)
				startX = SceneMain.getInstance().map.smallMap.width - _bitmapdata.width;
			if(startY > SceneMain.getInstance().map.smallMap.height - _bitmapdata.height)
				startY = SceneMain.getInstance().map.smallMap.height - _bitmapdata.height;
			_bitmapdata.copyPixels(SceneMain.getInstance().map.smallMap,new Rectangle(startX,startY,_bitmapdata.width,_bitmapdata.height),new Point(0,0));
		}
	}
}